package br.usp.ime.origami.foldcut.util;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import br.usp.ime.origami.foldcut.packing.Disk;
import br.usp.ime.origami.foldcut.structures.simplegraph.Vertex;
import br.usp.ime.origami.foldcut.structures.winged.WingedEdge;
import br.usp.ime.origami.foldcut.structures.winged.WingedFace;
import br.usp.ime.origami.foldcut.structures.winged.WingedVertex;
import br.usp.ime.origami.model.Point;
import br.usp.ime.origami.model.SimplePoint;

public class QuadrilateralFolderTest extends TestCase
{

	private WingedFace internalFace;

	@Override
	protected void setUp() throws Exception
	{
		List<WingedVertex> vertices = new ArrayList<WingedVertex>();
		vertices.add(new WingedVertex(0, 0));
		vertices.add(new WingedVertex(1.5, 0));
		vertices.add(new WingedVertex(4, 0));
		vertices.add(new WingedVertex(4, 2.5));
		vertices.add(new WingedVertex(4, 4));
		vertices.add(new WingedVertex(2.5, 4));
		vertices.add(new WingedVertex(0, 4));
		vertices.add(new WingedVertex(0, 1.5));

		List<WingedEdge> edges = new ArrayList<WingedEdge>();
		for (int i = 0; i < 8; i++)
		{
			edges.add(new WingedEdge(vertices.get(i), vertices.get((i + 1) % 8)));
		}

		this.internalFace = new WingedFace(edges.get(0));
		WingedFace externalFace = new WingedFace(edges.get(0));

		Vertex v = new Vertex(0, 0);
		Disk[] disks = { new Disk(v, 1), new Disk(v, 2), new Disk(v, 3), new Disk(v, 4) };

		for (int i = 0; i < 8; i++)
		{
			edges.get(i).setCoveringDisk(disks[(i + 1) / 2 % 4]);
			edges.get(i).setCw(internalFace);
			edges.get(i).setCcw(externalFace);
			edges.get(i).setNextCcw(edges.get((i + 1) % 8));
			edges.get(i).setNextCw(edges.get((i + 1) % 8));
			edges.get(i).setPreviousCcw(edges.get((i - 1 + 8) % 8));
			edges.get(i).setPreviousCcw(edges.get((i - 1 + 8) % 8));
		}

	}

	public void testQuadrilateral()
	{
		QuadrilateralFolder qf = new QuadrilateralFolder();
		Molecule m = qf.foldQuadrilateral(internalFace);

		System.out.println(internalFace.inSequence());

	}

	public void testCalculateTangentEdges()
	{
		
		QuadrilateralFolder qf = new QuadrilateralFolder();
		Molecule m = qf.foldQuadrilateral(internalFace);

		List<TangentEdge> tangents = qf.getTangents();
		assertEquals(4, tangents.size());
		
		assertTrue(tangents.contains(new TangentEdge(new SimplePoint(1.5,1.5), new SimplePoint(0,1.5))));
		assertTrue(tangents.contains(new TangentEdge(new SimplePoint(1.5,1.5), new SimplePoint(1.5,0))));
		assertTrue(tangents.contains(new TangentEdge(new SimplePoint(2.5,2.5), new SimplePoint(4,2.5))));
		assertTrue(tangents.contains(new TangentEdge(new SimplePoint(2.5,2.5), new SimplePoint(2.5,4))));
	}
}
